#pragma once

#include <string>
#include <map>
#include <list>
#include "Frame.hxx"

using namespace std;

class HostSettings
{
public:
	int id;
	int port;
	std::string ipaddr;
	std::string user;
	std::string passwd;
	std::string paramfile;
	std::string savefile;
	HostSettings()
		: id(0),port(0),ipaddr("192.168.23.100"),
		user("admin"),passwd("888888"),paramfile(""),savefile("")
	{
	}

	void setHostSettings(int id, int port, const string& ipaddr,const string& user, 
		const string& passwd,const string& paramfile,const string& savefile)
	{
		this->id = id;
		this->port = port;
		this->ipaddr = ipaddr;
		this->user = user;
		this->passwd = passwd;
		this->paramfile = paramfile;
		this->savefile = savefile;
	}

};

class Mp4Settings
{
public:
	int ChannelId;
	string sourcefile;
	string paramfile;
	Mp4Settings():ChannelId(0),sourcefile(""),paramfile("")
	{

	}

	void setMp4Settings(int ChannelId,const string& sourcefile,const string& savefile)
	{
		this->ChannelId = ChannelId;
		this->sourcefile = sourcefile;
		this->paramfile = savefile;
	}

};

class YUVSettings
{
public:
	int ChannelId;
	string sourcefile;
	string paramfile;
	YUVSettings():ChannelId(0),sourcefile(""),paramfile("")
	{
	}
	void setYUVSettings(int ChannelId,const string& sourcefile,const string& savefile)
	{
		this->ChannelId = ChannelId;
		this->sourcefile = sourcefile;
		this->paramfile = savefile;
	}
};

class BoxCalibrationSettings
{
public:
	int  ChannelId;
	float frontPoint[8];
	float backPoint[8];
	BoxCalibrationSettings()
	{
		for (int i=0;i<8;i++)
		{
			frontPoint[i] = 0;
			backPoint[i] = 0;
		}
	}
	void setfrontPoint()
	{

	}
	void setbackPoint()
	{

	}
}; 

struct HostInfo
{
	char IpAddress[ 20 ];
	int Port;
	char UserName[ 20 ];
	char Password[ 20 ];
	char File[ 20 ];
	char SourceFile [20];

	BoxRect FrontBox;
	BoxRect BackBox;

	float *frontPoints;
	float *backPoints;

	HostInfo()
	{
		IpAddress[ 0 ] = '\0';
		Port = 0;
		UserName[ 0 ] = '\0';
		Password[ 0 ] = '\0';
		File[ 0 ] = '\0';		
		SourceFile[0] = '\0'; 
	}
};


class AppSetting
{
public:
	AppSetting(void);
	~AppSetting(void);

public:
	string m_Appname;
	DataType m_SourceDataType;
	SaveDataType m_SaveDataType;

	list<HostSettings> m_HostSettings;
	list<Mp4Settings> m_Mp4Settings;
	list<YUVSettings> m_YUVSettings;
	list<BoxCalibrationSettings> m_BoxCalibSetting;

public:
	void load(const char* pFilename);
	void save(const char* pFilename);
};

extern AppSetting appSetting;
extern HostInfo __gHostInfo[3];

void loadHostInfo2();
void loadPoints2();
void loadAppSetting(const char* pFilename);
void saveAppSetting(const char* pFilename);

void writePoints();
